/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import DAL.MyConnectUnit;
import DAL.MySQLConnect;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

/**
 *
 * @author MINHTU
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        System.out.println("Ket noi co ban:");
        MySQLConnect connect = new MySQLConnect("localhost", "root", "", "cafedb");
        ResultSet result1 = connect.excuteQuery("Select * from nhanvien");
        System.out.println(CountRow(result1));
        
        result1 = connect.excuteQuery("Select * from nhanvien where idnhanvien = 1");
        System.out.println(CountRow(result1));
       
        
        System.out.println("Ket noi nang cao");
        
        MyConnectUnit connect1 = new MyConnectUnit("localhost", "root", "", "cafedb");
        ResultSet result2 = connect1.Select("nhanvien");
        System.out.println(CountRow(result2));
        result2 = connect1.Select("nhanvien", "idnhanvien = 1");
        System.out.println(CountRow(result2));
        
        HashMap<String, Object> insertvalues = new HashMap<>();
        insertvalues.put("TenNhanVien", "Le Minh Tu");
        insertvalues.put("NgaySinh", "20101111");
        insertvalues.put("DiaChi", "TPHCM");
        insertvalues.put("SoDienThoai", "2311");
        System.out.println(connect1.Insert("NhanVien", insertvalues));
        
        
        
        HashMap<String, Object> updatevalues = new HashMap<>();
        updatevalues.put("TenNhanVien", "Hoang Vi");
        updatevalues.put("NgaySinh", "20101111");
        updatevalues.put("DiaChi", "TPHCM");
        updatevalues.put("SoDienThoai", "2010112311");
        System.out.println(connect1.Update("NhanVien", updatevalues, "IDNhanVien = 2"));
        
        System.out.println(connect1.Delete("NhanVien", "IDNhanVien = 1"));
        
        connect1.Close();
        
    }
    
     // Đếm số dùng trong Resource
    protected static int CountRow(ResultSet result) throws SQLException{
        int count=0;
        while(result.next()){
            count++;
            //result.getObject("TenHS");
            //result.getObject("TenHS");
        }
        return count;
    }
}
